import scrapy


class BossSpider(scrapy.Spider):
    name = 'boss'
    # allowed_domains = ['www.xxx.com']
    # FIXME：弹出了个登录窗口。。。获取不到源代码。。。恶心啊！！！
    start_urls = ['https://www.zhipin.com/job_detail/?query=python&city=101010100&industry=&position=']

    def parse(self, response):
        li_list = response.xpath('//*[@id="main"]/div/div[3]/ul/li')
        print(li_list)
        for li in li_list:
            job_name = li.xpath('./div/div[1]/div[1]/div/div[1]/span[1]/a/text()')[0].extract()
            print(job_name)
            detail_url = 'https://www.zhipin.com'+li.xpath('./div/div[1]/div[1]/div/div[1]/span[1]/a/@href')[0].extract()
            # 手动发送请求，对详情页发送请求获取页面源数据
            yield scrapy.Request(url=detail_url, callback=self.parse_data)
        pass
    def parse_data(self, response):
        job_data = response.xpath('//*[@id="main"]/div[3]/div/div[2]/div[2]/div[1]/div').extract()
        job_data = ''.join(job_data)
        print(job_data)
        pass

